package com.jhws.business.face.bo;


import com.jhws.business.face.service.FaceService;
import com.jhws.core.dataUpdate.bo.DataUpdateObject;
import com.jhws.core.dataUpdate.bo.IDataUpdateModule;
import com.jhws.core.dataUpdate.service.DataUpdateService;
import com.jhws.core.exception.BizException;
import com.jhws.util.DateUtil;
import com.jhws.util.StringUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Component
public class FaceDataUpdate implements IDataUpdateModule {
    static public String FACE = "face";
    private String [] name = {FACE};
    @Resource
    private FaceService faceService;
    @Resource
    private DataUpdateService dataUpdateService;


    @Override
    public String [] getModuleName() {
        return name;
    }

    @Override
    public DataUpdateObject getUserModuleData(String username, String ownerCode, Long timeStamp, String module, Map<String, String> moduleParams) throws Exception {
        String commCode = MapUtils.getString(moduleParams, "commCode");
        String building = MapUtils.getString(moduleParams, "building");
        String unit = MapUtils.getString(moduleParams, "unit");
        if (timeStamp == null || StringUtils.isEmpty(commCode)) throw new BizException("参数错误！");
        String where = "where comm_code = '" + commCode + "'";
        if (StringUtils.isNotEmpty(building) && StringUtils.isNotEmpty(unit)) {
            where += " and building = '" + building + "' and unit = '" + unit + "'";
        }

        where += " and timestamp > '" + timeStamp + "'";
        return new DataUpdateObject(faceService.getFaceInfosByWhere(where, true));
    }

    @Override
    public DataUpdateObject getLabelModuleData(String label, Long timeStamp, String module, Map<String, String> moduleParams) throws Exception {
        return null;
    }

    @Override
    @PostConstruct
    public void registerModule() {
        dataUpdateService.registerModule(this);
    }
}
